#include <iostream>
using namespace std;

const int kMaxId = 1e6 + 10;

int id_last[kMaxId];

int main() {
  freopen("proximity.in", "r", stdin);
  freopen("proximity.out", "w", stdout);
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, k, id;
  int ans = -1;

  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> id;
    if (id_last[id] != 0) {
      if (i + 1 - id_last[id] <= k) {
        ans = max(ans, id);
      }
    }
    id_last[id] = i + 1;
  }
  cout << ans << "\n";
  return 0;
}